﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathematicallySafe.HeadCounter.Data.Common;
using MathematicallySafe.HeadCounter.Data;
using MathematicallySafe.HeadCounter.Data.Models;
using StructureMap;

namespace MathematicallySafe.HeadCounter.Services.Calculators
{
    public class GearMetricCalculator : Processor<Raider>
    {
        private static readonly IHeadCounterService HeadCounterService = ObjectFactory.GetInstance<IHeadCounterService>();

        protected override void Process(Raider raider)
        {
            var options = HeadCounterService.Options;

            if (raider.EquippedLoot.Count() > 0)
            {
                // GearScore assumes an item at current iLevelBase for missing items (i.e. 0).

                raider.AverageILevel = raider.EquippedLoot.Average(l => l.iLevel);
                raider.GearScore = raider.EquippedLoot.Sum(l => l.LootValue(raider));
                raider.ProgressionItemsCount = raider.EquippedLoot.Count(l => l.iLevel >= options.iLevelProgression);
                raider.LowLevelItemsCount = raider.EquippedLoot.Count(l => l.iLevel < options.iLevelBase);
            }
        }
    }
}
